//
//  UserModel.m
//  OCQ_API_Test
//
//  Created by 故乡的云  on 2017/5/4.
//  Copyright © 2017年 故乡的云 . All rights reserved.
//

#import "UserModel.h"

@implementation UserModel
static UserModel *user_;
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{ // 保证线程安全
        user_ = [super allocWithZone:zone];
    });
    return user_;
}

+ (instancetype)sharedUserModel {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        user_ = [[self alloc] init];
        [user_ userLogin];
    });
    
    return user_;
}

- (void)userLogin {
    
//    __weak UserModel *weakSelf = self;
    NSString *urlStr = @"http://10.10.2.184:1080/mobileApp/login?build=iOS_4.1";
    NSDictionary *paras = @{
                            @"mobilePhone" : @"18566201101",
                            @"password" : @"123456",
                            @"disableDes" : @"true",
                            @"loginedIp" : @"10.10.3.124",
                            @"device" : @"Simulator",
                            @"flag" : @"1",
                            @"appv-ver" : @"3.5.2"
                            };
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:urlStr parameters:paras progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([[responseObject allKeys] containsObject:@"error"]) {
            gxdy_Log(@"登录失败：%@",responseObject);
            return ;
        }
        
        gxdy_Log(@"登录成功！");
        user_ = [UserModel mj_objectWithKeyValues:responseObject];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        gxdy_Log(@"error!,请求失败！");
    }];
}

@end
